package com.huowei.htzy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.huowei.htzy.R;
import com.huowei.htzy.modle.Home7;
import com.huowei.htzy.util.ViewHolderUtil;

import java.util.List;

/**
 * Created by huowei on 2016/10/11.
 */

public class HomeGridAdapter extends BaseAdapter{
    private List<Home7> home7s;
    private Context context;
    private final RequestManager with;

    public HomeGridAdapter(List<Home7> home7s, Context context) {
        this.home7s = home7s;
        this.context = context;
        with = Glide.with(context);
    }

    @Override
    public int getCount() {
        return home7s.size();
    }

    @Override
    public Object getItem(int position) {
        return home7s.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.new_grid_adapter, null);
        }
        ImageView gGoodsImage = ViewHolderUtil.get(convertView,R.id.g_goods_image);
        TextView gGoodsName = ViewHolderUtil.get(convertView,R.id.g_goods_name);
        TextView gGoodsPromotionPrice = ViewHolderUtil.get(convertView,R.id.g_goods_promotion_price);
        Home7 home7 = home7s.get(position);
        if (home7.getGoods_name().length()>10) {
           gGoodsName.setText(home7.getGoods_name().substring(0,9)+"...");
        }else {
            gGoodsName.setText(home7.getGoods_name());
        }
        with.load(home7.getGoods_image()).into(gGoodsImage);
        gGoodsPromotionPrice.setText("￥"+home7.getGoods_promotion_price());
        return convertView;
    }

}
